//
//  LMWallTableViewCell.m
//  ZiJinLian
//
//  Created by 🐛 on 2018/1/23.
//  Copyright © 2018年 lzy. All rights reserved.
//

#import "LMWallTableViewCell.h"

@implementation LMWallTableViewCell

-(instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier{
    if ([super initWithStyle:style reuseIdentifier:reuseIdentifier]) {
        
    }
    return self;
}
-(void)setModel:(LMWishModel *)model{
    if (![_model isEqual:model]&&model!=nil) {
        _model=model;
        [self creatView];
    }
}
-(void)creatView{
    NSLog(@"---%@",_model.nickName);
    UIImage *images = [UIImage imageNamed:@"image_textbox"];
    
    // 设置左边端盖宽度
    NSInteger leftCapWidth = images.size.width * 0.5;
    // 设置上边端盖高度
    NSInteger topCapHeight = images.size.height * 0.5;
    
    UIImage *newImage = [images stretchableImageWithLeftCapWidth:leftCapWidth topCapHeight:topCapHeight];
    //背景
    UIImageView * backImage=[[UIImageView alloc]init];
    backImage.image= newImage;
    //ViewRadius(backImage, 20);
    [self.contentView addSubview:backImage];
    
    
    //头像
    UIImageView * image=[[UIImageView alloc]initWithFrame:CGRectMake(20, 10, 40, 40)];
    [image sd_setImageWithURL:[NSURL URLWithString:_model.avatar] placeholderImage:[UIImage imageNamed:@""]];
    ViewRadius(image, 20);
    [self.contentView addSubview:image];
    UILabel *userLabel=[[UILabel alloc]init];
    userLabel.text=_model.nickName;
    userLabel.textColor=Red_Color;
    userLabel.font=FontAndStyle12;
    [self.contentView addSubview:userLabel];
    NSMutableArray *array=[NSMutableArray array];
    for (prayModel *model in _model.prayInfoattr) {
        [array addObject:model.name];
    }
    UILabel *titleLabel=[[UILabel alloc]init];
    titleLabel.text=[array componentsJoinedByString:@" "];
    titleLabel.textColor=TextColor6;
    titleLabel.font=FontAndStyle12;
    [self.contentView addSubview:titleLabel];
    
    UILabel *contentLabel=[[UILabel alloc]init];
    contentLabel.text=_model.prayInfo;
    contentLabel.textColor=TextColor6;
    contentLabel.font=FontAndStyle12;
    [self.contentView addSubview:contentLabel];
   
    
    
    
    CGSize nameSize=[_model.nickName sizeWithAttributes:@{NSFontAttributeName:FontAndStyle12 }];
    CGSize titleSize=[titleLabel.text sizeWithAttributes:@{NSFontAttributeName:FontAndStyle12 }];
    CGSize contentSize=[_model.prayInfo sizeWithAttributes:@{NSFontAttributeName:FontAndStyle12 }];
    
    [userLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(image.mas_right).mas_offset(5);
        make.top.mas_equalTo(10);
        make.height.mas_equalTo(15);
    }];
    
    [titleLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(userLabel.mas_right).mas_offset(10);
        make.top.mas_equalTo(10);
        make.height.mas_equalTo(15);
    }];
    
    [contentLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(image.mas_right).mas_offset(5);
        make.top.mas_equalTo(userLabel.mas_bottom).mas_offset(5);
        make.height.mas_equalTo(15);
    }];
    
    //商品照片
    if (_model.imageUrl!=nil) {
        UIImageView * image=[[UIImageView alloc]initWithFrame:CGRectMake(20, 10, 40, 40)];
        [image sd_setImageWithURL:[NSURL URLWithString:_model.imageUrl] placeholderImage:[UIImage imageNamed:@""]];
        ViewRadius(image, 20);
        [self.contentView addSubview:image];
        [image mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.mas_equalTo(image.mas_left).mas_offset(-10);
            make.top.mas_equalTo(0);
            make.right.mas_equalTo(contentLabel.mas_right).mas_offset(20);
        }];
    }else{
        if(nameSize.width+10+titleSize.width>contentSize.width&&nameSize.width+10+titleSize.width<MainW-105) {
            
        }
    }
    
    
    
    
    
}
- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

@end
